{-# LANGUAGE ForeignFunctionInterface #-}
module HCstructures where
import Foreign
import Foreign.C

#include "tools_node.h"
#include "tools_rbtree.h"
#include "tools/intrbtree.h"


data Node=Node{
    node_get_prev:: !(Ptr ()),
    node_get_value:: !(Ptr ()),
    node_get_next:: !(Ptr ()),
    node_get_traits:: !(Ptr ())
}
-- instance Storable Node where
--     sizeOf _ = #{size Node}
--     alignment _ = #{alignment Node}
--     peek ptr =do
--         prev <- peek (#{ptr Node,Prev} ptr)
--         value <- peek (#{ptr Node, value} ptr)
--         next <- peek (#{ptr Node,Next} ptr)
--         traits <- peek (#{ptr Node, traits} ptr)
--         pure (Node prev value next traits)
--     poke ptr (Node prev value next traits)=do
--         poke (#{ptr Node,Prev} ptr) prev 
--         poke (#{ptr Node,value} ptr) value
--         poke (#{ptr Node,Next} ptr) next
--         poke (#{ptr Node,traits} ptr) traits

data RB_Tree_Node=RB_Tree_Node{
    rb_tree_node_get_left:: !(Ptr RB_Tree_Node),
    rb_tree_node_get_right:: !(Ptr RB_Tree_Node),
    rb_tree_node_get_parent:: !(Ptr RB_Tree_Node),
    rb_tree_node_get_data:: !(Ptr ()),
    rb_tree_node_get_prop:: !(Ptr ())
}

instance Storable RB_Tree_Node where
    sizeOf _ = #{size RB_Tree_Node}
    alignment _ = #{alignment RB_Tree_Node}
    peek ptr =do
        left<- peek (#{ptr RB_Tree_Node,left} ptr)
        right<- peek (#{ptr RB_Tree_Node,right} ptr)
        parent<- peek (#{ptr RB_Tree_Node,parent} ptr)
        hdata<- peek (#{ptr RB_Tree_Node, data} ptr)
        prop<- peek (#{ptr RB_Tree_Node,prop} ptr)
        pure (RB_Tree_Node left right parent hdata prop)
    poke ptr (RB_Tree_Node left right parent hdata prop)=do
        poke (#{ptr RB_Tree_Node,left} ptr) left
        poke (#{ptr RB_Tree_Node,right} ptr) right
        poke (#{ptr RB_Tree_Node,parent} ptr) parent
        poke (#{ptr RB_Tree_Node,data} ptr) hdata
        poke (#{ptr RB_Tree_Node,prop} ptr) prop
